package home.pkg

import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.ColorUtils
import home.pkg.databinding.HomeActBinding
import home.pkg.manager.HomeManager
import home.pkg.vm.HomeVm
import lib.base.BaseAct
import lib.rv.IRvAdapterBind

/**
 *  author: luoXiong
 *  e-mail: 382060748@qq.com
 *  date: 2021/7/25 21:31
 *  version: 1.0
 *  desc:
 */

class HomeAct : BaseAct<HomeActBinding, HomeVm, HomeManager>() {

    override val layoutId: Int = R.layout.home_act
    override fun initView() {
        val itemList = arrayListOf<OrderVhModel>()
        for (index in 0..20) {
            val model = OrderVhModel()
            model.title = "我w是$index"
            itemList.add(model)
        }
//        val ap = OrderAdapter()
//        ap.setItems(itemList)
        // getB().rv.adapter = ap

        val adapter_listener = object : IRvAdapterBind<OrderVhModel> {
            override fun getItemList(): List<OrderVhModel> {
                return itemList
            }
        }
        getB().rvApBind = adapter_listener as IRvAdapterBind<Any>
    }

    override fun doBusiness(savedInstanceState: Bundle?) {
        var index1: Int = 0
        var index2: Int = 0
        getB().btn1.setOnClickListener {
            getVm().name1.value = "我是"+(++index1)
            getVm().imgRes.value = ContextCompat.getDrawable(it.context,android.R.drawable.bottom_bar)!!
        }
        getB().btn2.setOnClickListener {
            getVm().name2.postValue( "他是"+(++index2))
            getVm().imgRes.value = ContextCompat.getDrawable(it.context,android.R.drawable.btn_dialog)!!
        }
        getB().btn3.setOnClickListener {
            getVm().imgRes.value = ColorDrawable(ColorUtils.getColor(android.R.color.transparent))!!
            getVm().imgRes.value = null
        }
    }

}